package com.project.erp.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionSupport;
import com.project.erp.common.Constants;

public class BaseAction extends ActionSupport{

	private static final long serialVersionUID = 2075595160414505059L;

	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	//页面传过来的页码
	private int page;
	
	//页面传过来的一页多少条数据
	private int rows;
	
	//可以用于页面返回结果集信息的Map对象
	private Map<String, Object> resultMap = new HashMap<String, Object>();
	
	public int getPage() {
		return page;
	}
	
	public void setPage(int page) {
		this.page = page;
	}
	
	public int getRows() {
		return rows;
	}
	
	public void setRows(int rows) {
		this.rows = rows;
	}

	public Map<String, Object> getResultMap() {
		return resultMap;
	}

	public void setResultMap(Map<String, Object> resultMap) {
		this.resultMap = resultMap;
	}
	
	/**
	 * 获得request
	 * 
	 * @return
	 */
	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	/**
	 * 获得response
	 * 
	 * @return
	 */
	public HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}

	/**
	 * 获得session
	 * 
	 * @return
	 */
	public HttpSession getSession() {
		return getRequest().getSession();
	}

	/**
	 * 获得servlet上下文
	 * 
	 * @return
	 */
	public ServletContext getServletContext() {
		return ServletActionContext.getServletContext();
	}

	public String getRealyPath(String path) {
		return getServletContext().getRealPath(path);
	}
	
	/**根据key值取得系统参数
	 * 
	 * @param firstKey
	 * @param secondKey
	 * @return
	 */
	public String getParamByKeys(String firstKey,String secondKey){
		@SuppressWarnings("unchecked")
		Map<String,Map<String, String>> paramMap = (Map<String,Map<String, String>>)this.getServletContext().getAttribute(Constants.PARAMS_MAP);
		return paramMap.get(firstKey).get(secondKey);
	}
}
